{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "46230c00-c294-49ab-a0da-9568808f7525",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T03:47:26.970950Z",
     "iopub.status.busy": "2022-05-08T03:47:26.970590Z",
     "iopub.status.idle": "2022-05-08T03:47:27.490116Z",
     "shell.execute_reply": "2022-05-08T03:47:27.489632Z",
     "shell.execute_reply.started": "2022-05-08T03:47:26.970878Z"
    }
   },
   "outputs": [],
   "source": [
    "# 导入包\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fed88dab-ee10-419b-ab01-ae937394f6c3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T17:35:41.307676Z",
     "iopub.status.busy": "2022-05-08T17:35:41.307430Z",
     "iopub.status.idle": "2022-05-08T17:35:41.316233Z",
     "shell.execute_reply": "2022-05-08T17:35:41.314966Z",
     "shell.execute_reply.started": "2022-05-08T17:35:41.307650Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    one  two\n",
      "a  1.60  NaN\n",
      "b  8.20 -5.6\n",
      "c   NaN  NaN\n",
      "d  0.86 -2.4\n"
     ]
    }
   ],
   "source": [
    "# 创建DataFrame对象\n",
    "pd1 = pd.DataFrame(\n",
    "    [[1.6, np.nan], [8.2, -5.6], [np.nan, np.nan], [0.86, -2.4]],\n",
    "    columns=[\"one\", \"two\"],\n",
    "    index=list(\"abcd\"),\n",
    ")\n",
    "print(pd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "94c15760-7001-4c88-9ecc-9fb58497a002",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T17:47:05.561699Z",
     "iopub.status.busy": "2022-05-08T17:47:05.561446Z",
     "iopub.status.idle": "2022-05-08T17:47:05.568353Z",
     "shell.execute_reply": "2022-05-08T17:47:05.567475Z",
     "shell.execute_reply.started": "2022-05-08T17:47:05.561673Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "one    10.66\n",
      "two    -8.00\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 对df1进行求和计算，默认按列计算\n",
    "print(pd1.sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d113b294-1ee3-471d-b3dd-ae8cd52136db",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T17:56:38.229102Z",
     "iopub.status.busy": "2022-05-08T17:56:38.228834Z",
     "iopub.status.idle": "2022-05-08T17:56:38.234517Z",
     "shell.execute_reply": "2022-05-08T17:56:38.233453Z",
     "shell.execute_reply.started": "2022-05-08T17:56:38.229075Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a    1.60\n",
      "b    2.60\n",
      "c    0.00\n",
      "d   -1.54\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 对df1进行求和计算，指定按行计算\n",
    "print(pd1.sum(axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7e3b459b-1303-4e47-b8b4-c82e178feba4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T18:10:33.131738Z",
     "iopub.status.busy": "2022-05-08T18:10:33.131463Z",
     "iopub.status.idle": "2022-05-08T18:10:33.138155Z",
     "shell.execute_reply": "2022-05-08T18:10:33.137061Z",
     "shell.execute_reply.started": "2022-05-08T18:10:33.131696Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a     NaN\n",
      "b    2.60\n",
      "c     NaN\n",
      "d   -1.54\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 对df1进行求和计算，指定按行计算\n",
    "print(pd1.sum(axis=1, skipna=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f2cbea8e-57b6-4227-bb79-70451203e044",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T18:42:49.453704Z",
     "iopub.status.busy": "2022-05-08T18:42:49.452900Z",
     "iopub.status.idle": "2022-05-08T18:42:49.461857Z",
     "shell.execute_reply": "2022-05-08T18:42:49.461060Z",
     "shell.execute_reply.started": "2022-05-08T18:42:49.453674Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "one    b\n",
       "two    d\n",
       "dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求最大值的索引值\n",
    "pd1.idxmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ea31672a-0304-4ccb-8162-61a16913afa5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T18:50:07.379242Z",
     "iopub.status.busy": "2022-05-08T18:50:07.378898Z",
     "iopub.status.idle": "2022-05-08T18:50:07.385611Z",
     "shell.execute_reply": "2022-05-08T18:50:07.384370Z",
     "shell.execute_reply.started": "2022-05-08T18:50:07.379210Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     one  two\n",
      "a   1.60  NaN\n",
      "b   9.80 -5.6\n",
      "c    NaN  NaN\n",
      "d  10.66 -8.0\n"
     ]
    }
   ],
   "source": [
    "# 累计求和\n",
    "print(pd1.cumsum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c54cf742-4412-4efa-8b71-b60db6adcfff",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T18:58:03.330169Z",
     "iopub.status.busy": "2022-05-08T18:58:03.329840Z",
     "iopub.status.idle": "2022-05-08T18:58:03.340809Z",
     "shell.execute_reply": "2022-05-08T18:58:03.340105Z",
     "shell.execute_reply.started": "2022-05-08T18:58:03.330142Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            one       two\n",
      "count  3.000000  2.000000\n",
      "mean   3.553333 -4.000000\n",
      "std    4.041105  2.262742\n",
      "min    0.860000 -5.600000\n",
      "25%    1.230000 -4.800000\n",
      "50%    1.600000 -4.000000\n",
      "75%    4.900000 -3.200000\n",
      "max    8.200000 -2.400000\n"
     ]
    }
   ],
   "source": [
    "# 生成多种汇总统计数据\n",
    "print(pd1.describe())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d41b7783-3d6f-4f62-85fa-f487caed428b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T19:09:21.353015Z",
     "iopub.status.busy": "2022-05-08T19:09:21.352766Z",
     "iopub.status.idle": "2022-05-08T19:09:21.357932Z",
     "shell.execute_reply": "2022-05-08T19:09:21.357297Z",
     "shell.execute_reply.started": "2022-05-08T19:09:21.352989Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0     a\n",
      "1     c\n",
      "2     c\n",
      "3     d\n",
      "4     e\n",
      "5     a\n",
      "6     c\n",
      "7     c\n",
      "8     d\n",
      "9     e\n",
      "10    a\n",
      "11    c\n",
      "12    c\n",
      "13    d\n",
      "14    e\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "# 创建Series对象\n",
    "s1 = pd.Series([\"a\",\"c\",\"c\",\"d\",\"e\"]*3)\n",
    "print(s1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c29f766d-240f-41f1-bca1-23bdfb63a819",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-05-08T19:13:03.485962Z",
     "iopub.status.busy": "2022-05-08T19:13:03.485717Z",
     "iopub.status.idle": "2022-05-08T19:13:03.494972Z",
     "shell.execute_reply": "2022-05-08T19:13:03.494091Z",
     "shell.execute_reply.started": "2022-05-08T19:13:03.485935Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count     15\n",
       "unique     4\n",
       "top        c\n",
       "freq       6\n",
       "dtype: object"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成多种汇总统计数据\n",
    "s1.describe()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
